package com.vcredit.creditcat.service.auth;

import java.text.ParseException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Map.Entry;

import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.vcredit.creditcat.dto.creditrepository.ItemStatusDto;
import com.vcredit.creditcat.dto.speedloan.SpeedloanAuthItemDto;
import com.vcredit.creditcat.enumtype.AuthItemEnum;
import com.vcredit.creditcat.enumtype.BankCardTypeEnum;
import com.vcredit.creditcat.model.AddressList;
import com.vcredit.creditcat.model.AuthAccumulation;
import com.vcredit.creditcat.model.AuthAlipay;
import com.vcredit.creditcat.model.AuthCreditcard;
import com.vcredit.creditcat.model.AuthIdentity;
import com.vcredit.creditcat.model.AuthItem;
import com.vcredit.creditcat.model.AuthJd;
import com.vcredit.creditcat.model.AuthMobile;
import com.vcredit.creditcat.model.AuthNetcredit;
import com.vcredit.creditcat.model.AuthSchoolInfo;
import com.vcredit.creditcat.model.AuthSecredit;
import com.vcredit.creditcat.model.AuthSocial;
import com.vcredit.creditcat.model.AuthTaobao;
import com.vcredit.creditcat.model.CallLog;
import com.vcredit.creditcat.model.CreditAssure;
import com.vcredit.creditcat.model.Cust;
import com.vcredit.creditcat.model.CustCard;
import com.vcredit.creditcat.model.CustSupplementItem;
import com.vcredit.creditcat.model.ProcessSpecialItem;
import com.vcredit.creditcat.model.ProductSupplementItem;
import com.vcredit.creditcat.model.Relative;
import com.vcredit.creditcat.model.base.AbstractItem;
import com.vcredit.creditcat.service.AddressListService;
import com.vcredit.creditcat.service.AuthAccumulationService;
import com.vcredit.creditcat.service.AuthAlipayService;
import com.vcredit.creditcat.service.AuthCreditcardService;
import com.vcredit.creditcat.service.AuthIdentityService;
import com.vcredit.creditcat.service.AuthItemService;
import com.vcredit.creditcat.service.AuthJdService;
import com.vcredit.creditcat.service.AuthMobileService;
import com.vcredit.creditcat.service.AuthNetcreditService;
import com.vcredit.creditcat.service.AuthPersonalInfoService;
import com.vcredit.creditcat.service.AuthSchoolInfoService;
import com.vcredit.creditcat.service.AuthSecreditService;
import com.vcredit.creditcat.service.AuthSocialService;
import com.vcredit.creditcat.service.AuthTaobaoService;
import com.vcredit.creditcat.service.CallLogService;
import com.vcredit.creditcat.service.CreditAssureService;
import com.vcredit.creditcat.service.CustCardService;
import com.vcredit.creditcat.service.CustCreditRepositoryService;
import com.vcredit.creditcat.service.CustSupplementItemService;
import com.vcredit.creditcat.service.ProductSupplementItemService;
import com.vcredit.creditcat.service.RelativeService;
import com.vcredit.creditcat.service.speedloan.ProcessSpecialItemService;
import com.vcredit.creditcat.util.Utility;
import com.vcredit.creditcat.vo.AuthItemCheckResultVo;
import com.vcredit.creditcat.vo.auth.AuthAccumulationExt;
import com.vcredit.creditcat.vo.auth.AuthAlipayExt;
import com.vcredit.creditcat.vo.auth.AuthCreditcardExt;
import com.vcredit.creditcat.vo.auth.AuthIdentityExt;
import com.vcredit.creditcat.vo.auth.AuthJdExt;
import com.vcredit.creditcat.vo.auth.AuthMobileExt;
import com.vcredit.creditcat.vo.auth.AuthNetcreditExt;
import com.vcredit.creditcat.vo.auth.AuthPersonalInfoExt;
import com.vcredit.creditcat.vo.auth.AuthSchoolInfoExt;
import com.vcredit.creditcat.vo.auth.AuthSecreditExt;
import com.vcredit.creditcat.vo.auth.AuthSocialExt;
import com.vcredit.creditcat.vo.auth.AuthTaobaoExt;
import com.vcredit.creditcat.vo.auth.CreditAssureExt;
import com.vcredit.creditcat.vo.auth.CustCardExt;
import com.vcredit.creditcat.vo.auth.RelativeListExt;


@Service
public class AuthItemExtService {

	public static List<Integer> needCheckExpireItems; // 需要检查过期的认证项

	static {
		needCheckExpireItems = new ArrayList<Integer>();
		needCheckExpireItems.add(16); // 手机认证
		needCheckExpireItems.add(64); // 央行征信
		needCheckExpireItems.add(128); // 芝麻分
		needCheckExpireItems.add(256); // 社保
		needCheckExpireItems.add(512); // 公积金
		needCheckExpireItems.add(1024); // 支付宝
		needCheckExpireItems.add(2048); // 淘宝
		needCheckExpireItems.add(4096); // 京东
		needCheckExpireItems.add(8192); // 信用卡
		needCheckExpireItems.add(32768); // 机构版征信
	}

	@Autowired
	private CustCreditRepositoryService repositoryService;
	@Autowired
	private AuthItemService authItemService;
	@Autowired
	private CustSupplementItemService custSupplementItemService;
	@Autowired
	private ProductSupplementItemService productSupplementItemService;
	@Autowired
	private ProcessSpecialItemService processSpecialItemService;

	/** 认证详情Service **/
	@Autowired
	private AuthPersonalInfoService authPersonalInfoService;
	@Autowired
	private AuthIdentityService authIdentityService;
	@Autowired
	private CustCardService custCardService;
	@Autowired
	private AuthMobileService authMobileService;
	@Autowired
	private AuthSchoolInfoService authSchoolInfoService;
	@Autowired
	private AuthNetcreditService authNetcreditService;
	@Autowired
	private AuthSecreditService authSecreditService;
	@Autowired
	private AuthSocialService authSocialService;
	@Autowired
	private AuthAccumulationService authAccumulationService;
	@Autowired
	private AuthAlipayService authAlipayService;
	@Autowired
	private AuthTaobaoService authTaobaoService;
	@Autowired
	private AuthJdService authJdservice;
	@Autowired
	private AuthCreditcardService authCreditcardService;
	@Autowired
	private RelativeService relativeService;
	@Autowired
	private CreditAssureService creditAssureService;
	
	@Autowired
	private AddressListService addressListService;
	@Autowired
	private CallLogService callLogService;

	public AuthItemCheckResultVo getCheckResultByCustAndProduct(Cust cust,long productId,
			List<CustSupplementItem> custSupplementItemList,
			List<ItemStatusDto> itemStatusDtoList) throws Exception {

		if(null == custSupplementItemList && null == itemStatusDtoList) {
			/**** 校验认证完成状态 *****/
			// 获取用户对该产品所需的认证补充项的认证信息
			custSupplementItemList = custSupplementItemService.findAllItemsByCustAndProduct(cust, productId);
			
			// 获取用户对该产品的认证项状态
			itemStatusDtoList = this.getItemStatusDtoByCustAndProduct(cust, productId);
			
		}
		
		Map<Long, CustSupplementItem> supplementItemMap = this.getSupplementItemMap(custSupplementItemList);

		// 判断认证项和补充认证项的综合状态
		//int checkStatus = this.checkAllItemsStatus(itemStatusDtoList, custSupplementItemList);

		// 如果不是全部完成
//		if (checkStatus != 1) {
//			return new AuthItemCheckResultVo(checkStatus, null, itemStatusDtoList,
//					null, supplementItemMap, null);
//		}

		/***** 校验认证项过期状态 *****/
		// 获取用户认证详情
		Map<Integer, AbstractItem> custAuthInfo = this.getCustAuthInfo(
				itemStatusDtoList, cust);

		// 获取失效的原始认证项
		List<Integer> expireAuthItems = this.getExpireAuthItems(custAuthInfo);
		// 获取失效的补充认证项
		List<Long> expireSupplementItems = this.getExpireSupplementItems(custSupplementItemList);
		
		if(expireAuthItems.size() > 0 || expireSupplementItems.size() > 0) {
			return new AuthItemCheckResultVo(5, "认证项失效", itemStatusDtoList, custAuthInfo, supplementItemMap, expireAuthItems,expireSupplementItems);
		}
		
		return new AuthItemCheckResultVo(1, null, itemStatusDtoList, custAuthInfo, supplementItemMap, expireAuthItems,expireSupplementItems);
	}

	private Map<Long,CustSupplementItem> getSupplementItemMap(List<CustSupplementItem> custSupplementItems) {
		Map<Long,CustSupplementItem> result = new HashMap<Long,CustSupplementItem>();
		for (CustSupplementItem custSupplementItem : custSupplementItems) {
			result.put(custSupplementItem.getSupplementItemId(), custSupplementItem);
		}
		return result;
	}

	/**
	 * 获取过期的原始认证项
	 * 
	 * @author zhaoqi01
	 * @param custAuthInfo
	 * @return
	 * @throws ParseException
	 */
	public List<Integer> getExpireAuthItems(
			Map<Integer, AbstractItem> custAuthInfo) throws ParseException {
		List<Integer> result = new ArrayList<Integer>();
		
		for (Entry<Integer, AbstractItem> entry : custAuthInfo.entrySet()) {
			Integer itemCode = entry.getKey();
			AbstractItem abstractItem = entry.getValue();
			
			if (needCheckExpireItems.contains(itemCode) && abstractItem.computeExpire()) {
				result.add(itemCode);
			}
		}
		return result;
	}
	
	/**
	 * 获取过期的补充认证项
	 * @author zhaoqi01
	 * @param custSupplementItemList
	 * @return
	 * @throws ParseException 
	 */
	public List<Long> getExpireSupplementItems(
			List<CustSupplementItem> custSupplementItemList) throws ParseException {
		List<Long> result = new ArrayList<Long>();
		if(Utility.isNullOrEmpty(custSupplementItemList))
			return result;
		
		for (CustSupplementItem custSupplementItem : custSupplementItemList) {
			if(custSupplementItem.computeExpire())
				result.add(custSupplementItem.getId());
		}
		return result;
	}

	/**
	 * 获取用户认证详情信息
	 * 
	 * @author zhaoqi01
	 * @return
	 */
	public Map<Integer, AbstractItem> getCustAuthInfo(
			List<ItemStatusDto> itemStatusDtoList, Cust cust) {
		Map<Integer, AbstractItem> result = new HashMap<Integer, AbstractItem>();
		for (ItemStatusDto itemStatusDto : itemStatusDtoList) {
			int itemCode = itemStatusDto.getItemCode();
			Long lastProccessId = cust.getLastProccessId();
			if (itemCode == AuthItemEnum.BASE_INFO.getCode()) { // 基本信息
				AuthPersonalInfoExt authPersonalInfoExt = authPersonalInfoService.findExtByCust(cust);
				if(null != authPersonalInfoExt) {
					authPersonalInfoExt.setItemCode(itemCode);
					result.put(itemCode, authPersonalInfoExt);
				}

			}

			else if (itemCode == AuthItemEnum.IDENTITY_REAL.getCode()) { // 高级实名
				AuthIdentity identity = authIdentityService
						.findByProcessId(lastProccessId);
				if(identity!=null){
					identity.setItemCode(itemCode);
					AuthIdentityExt target = new AuthIdentityExt();
					BeanUtils.copyProperties(identity, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.DEBIT_CARD.getCode()) { // 绑卡认证
				CustCard custCard = custCardService.findByCustIdAndCardType(
						cust.getCustId(), BankCardTypeEnum.DEBIT).get(0);

				if(custCard!=null){
					custCard.setItemCode(itemCode);
					CustCardExt target = new CustCardExt();
					BeanUtils.copyProperties(custCard, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.MOBILE.getCode()) { // 手机认证
				AuthMobile mobile = authMobileService
						.findByProcessIdAndType(lastProccessId,0);

				if(mobile!=null){
					mobile.setItemCode(itemCode);
					AuthMobileExt target = new AuthMobileExt();
					BeanUtils.copyProperties(mobile, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.EDUCATION.getCode()) { // 学历认证
				AuthSchoolInfo school = authSchoolInfoService
						.findByProccessId(lastProccessId);

				if(school!=null){
					school.setItemCode(itemCode);
					AuthSchoolInfoExt target = new AuthSchoolInfoExt();
					BeanUtils.copyProperties(school, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.BANK_CREDIT.getCode()) { // 央行征信
				AuthNetcredit netCredit = authNetcreditService
						.findByProcessId(lastProccessId);

				if(netCredit!=null){
					netCredit.setItemCode(itemCode);
					AuthNetcreditExt target = new AuthNetcreditExt();
					BeanUtils.copyProperties(netCredit, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.SESAME_CREDIT.getCode()) { // 芝麻分
				AuthSecredit secredit = authSecreditService
						.findByProcessId(lastProccessId);

				if(secredit!=null){
					secredit.setItemCode(itemCode);
					AuthSecreditExt target = new AuthSecreditExt();
					BeanUtils.copyProperties(secredit, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.SOCIAL_CREDIT.getCode()) { // 社保
				AuthSocial social = authSocialService
						.findByProcessId(lastProccessId);

				if(social!=null){
					social.setItemCode(itemCode);
					AuthSocialExt target = new AuthSocialExt();
					BeanUtils.copyProperties(social, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.FUND_CREDIT.getCode()) { // 公积金
				AuthAccumulation accumulation = authAccumulationService
						.findByProccessId(lastProccessId);

				if(accumulation!=null){
					accumulation.setItemCode(itemCode);
					AuthAccumulationExt target = new AuthAccumulationExt();
					BeanUtils.copyProperties(accumulation, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.ALIPAY.getCode()) { // 支付宝
				AuthAlipay alipay = authAlipayService
						.findByProcessId(lastProccessId);

				if(alipay!=null){
					alipay.setItemCode(itemCode);
					AuthAlipayExt target = new AuthAlipayExt();
					BeanUtils.copyProperties(alipay, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.TAOBAO.getCode()) { // 淘宝
				AuthTaobao taobao = authTaobaoService
						.findByProcessId(lastProccessId);

				if(taobao!=null){
					taobao.setItemCode(itemCode);
					AuthTaobaoExt target = new AuthTaobaoExt();
					BeanUtils.copyProperties(taobao, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.JINGDONG.getCode()) { // 京东
				AuthJd jd = authJdservice.findByProcessId(lastProccessId);

				if(jd!=null){
					jd.setItemCode(itemCode);
					AuthJdExt target = new AuthJdExt();
					BeanUtils.copyProperties(jd, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.CREDIT_CARD.getCode()) { // 信用卡
				AuthCreditcard creditcard = authCreditcardService
						.findByProcessId(lastProccessId);

				if(creditcard!=null){
					creditcard.setItemCode(itemCode);
					AuthCreditcardExt target = new AuthCreditcardExt();
					BeanUtils.copyProperties(creditcard, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.CONTACTS.getCode()) { // 紧急联系人
				List<Relative> relatives = relativeService.findByCustId(cust
						.getCustId());
				if(relatives!=null){
				// 查询用户对应的通讯录
				List<AddressList> addressList = addressListService.findByCustId(cust.getCustId());
				// 查询用户对应的通话记录
				List<CallLog> callLogList = callLogService.findByCustId(cust.getCustId());
				
				RelativeListExt relativeList = new RelativeListExt(relatives,addressList,callLogList);
					relativeList.setItemCode(itemCode);
					result.put(itemCode, relativeList);
				}

			}

			else if (itemCode == AuthItemEnum.FOREIGN_CREDIT.getCode()) { // 机构版征信
				CreditAssure creditAssure = creditAssureService
						.findByProcessId(lastProccessId);

				if(creditAssure!=null){
					creditAssure.setItemCode(itemCode);
					CreditAssureExt target = new CreditAssureExt();
					BeanUtils.copyProperties(creditAssure, target);

					result.put(itemCode, target);
				}

			}

			else if (itemCode == AuthItemEnum.VERIFY_FACE_PAIR.getCode()) { // 人脸识别认证
				AuthIdentity identity = authIdentityService
						.findByProcessId(lastProccessId);
				if(identity!=null){
					identity.setItemCode(itemCode);
					AuthIdentityExt target = new AuthIdentityExt();
					BeanUtils.copyProperties(identity, target);

					result.put(itemCode, target);
				}
			}
		}
		return result;
	}

	/**
	 * 检查认证项和补充认证项的综合状态
	 * 0、有未申请、申请中、已通过的认证项，但没有失败的认证项 
	 * 1、认证项全部通过
	 * 2、有申请中、已通过的认证项,没有失败和未申请的认证项 
	 * 3、有失败的认证项 
	 * 4、所有认证项都未申请
	 * @author zhaoqi01
	 * @param itemStatusDtos
	 * @return
	 */
	public int checkAllItemsStatus(List<ItemStatusDto> itemStatusDtos, List<CustSupplementItem> custSupplementItems) {
		int authItemsStatus = this.checkAuthItemsStatus(itemStatusDtos);
		int supplementItemsStatus = this.checkSupplementItemsStatus(custSupplementItems);
		
		if(custSupplementItems.size() == 0) {
			return authItemsStatus;
		}
		
		if(itemStatusDtos.size() == 0) {
			return supplementItemsStatus;
		}
		
		if(authItemsStatus == 3 || supplementItemsStatus == 3) {
			return 3;
		} 
		
		else if(authItemsStatus == 0 || supplementItemsStatus == 0) {
			return 0;
		} 
		
		else if(authItemsStatus == 4) {
			if(supplementItemsStatus == 4) {
				return 4;
			} else {
				return 0;
			}
		} 
		
		else if(supplementItemsStatus == 4) {
			if(authItemsStatus == 4) {
				return 4;
			} else {
				return 0;
			}
		}
		
		else if(authItemsStatus == 2 || supplementItemsStatus == 2) {
			return 2;
		} 
		
		else {
			return 1;
		}
	}
	
	/**
	 * 检查补充认证项状态
	 * 0、有未申请、申请中、已通过的认证项，但没有失败的认证项 
	 * 1、认证项全部通过
	 * 2、有申请中、已通过的认证项,没有失败和未申请的认证项 
	 * 3、有失败的认证项 
	 * 4、所有认证项都未申请
	 * @author zhaoqi01
	 * @param itemStatusDtos
	 * @return
	 */
	public int checkSupplementItemsStatus(List<CustSupplementItem> custSupplementItems) {
		List<Integer> statusList = new ArrayList<Integer>();
		for(CustSupplementItem supplementItem : custSupplementItems) {
			statusList.add(supplementItem.getStatus());
		}
		return this.handlerStatusList(statusList);
	}
	
	/**
	 * 检查认证项状态
	 * 0、有未申请、申请中、已通过的认证项，但没有失败的认证项 
	 * 1、认证项全部通过
	 * 2、有申请中、已通过的认证项,没有失败和未申请的认证项 
	 * 3、有失败的认证项 
	 * 4、所有认证项都未申请
	 * @author zhaoqi01
	 * @param itemStatusDtos
	 * @return
	 */
	public int checkAuthItemsStatus(List<ItemStatusDto> itemStatusDtos) {
		List<Integer> statusList = new ArrayList<Integer>();
		for (ItemStatusDto itemStatusDto : itemStatusDtos) {
			statusList.add(Integer.parseInt(itemStatusDto.getStatus()));
		}
		return this.handlerStatusList(statusList);
	}
	
	private int handlerStatusList(List<Integer> statusList) {
		if (statusList.contains(3))
			return 3; // 有失败的认证项

		else if (statusList.contains(0)) {
			if (!statusList.contains(1) && !statusList.contains(2))
				return 4; // 所有认证项都未申请
			else
				return 0;// 有未申请的认证项
		}

		else if (statusList.contains(2))
			return 2; // 有申请中的认证项
		else
			return 1; // 认证项全部通过
	}

	/**
	 * 获取用户对产品的原始认证项状态
	 * 
	 * @author zhaoqi01
	 * @param cust
	 * @param productId
	 * @return
	 * @throws Exception
	 */
	public List<ItemStatusDto> getItemStatusDtoByCustAndProduct(Cust cust,
			long productId) throws Exception {
		List<ItemStatusDto> result = new ArrayList<ItemStatusDto>();
		// 获取产品所需要的原始认证项（从快贷流程中获取）
		List<ProcessSpecialItem> specialItems = processSpecialItemService.findByProductId(productId);
		Map<Long, AuthItem> allAuthItem = authItemService.findAll();
		for (ProcessSpecialItem processSpecialItem : specialItems) {
			if(processSpecialItem.getItemType() == 0) {
				AuthItem authItem = allAuthItem.get(processSpecialItem.getItemId().longValue());
				ItemStatusDto statusDto = repositoryService.getStatus(
						authItem.getAuthCode() + "", 0, cust);
				result.add(statusDto);
			}
		}
		return result;
	}
	
	public List<SpeedloanAuthItemDto> getSpeedloanAuthItemsByCustAndProduct(Cust cust, Long productId) throws Exception {
		if(cust == null) 
			cust = new Cust();
		List<SpeedloanAuthItemDto> result = new ArrayList<SpeedloanAuthItemDto>();
		// 获取产品所需的所有认证项，包括补充认证项，从快贷流程中获取
		List<ProcessSpecialItem> specialItems = processSpecialItemService.findByProductId(productId);
		Map<Long, AuthItem> allAuthItem = authItemService.findAll();
		for (ProcessSpecialItem specialItem : specialItems) {
			SpeedloanAuthItemDto speedloanAuthItemDto = new SpeedloanAuthItemDto();
			if(specialItem.getItemType() == 0) { // 原认证项
				AuthItem authItem = allAuthItem.get(specialItem.getItemId().longValue());
				ItemStatusDto statusDto = repositoryService.getStatus(
						authItem.getAuthCode() + "", 0, cust);
				speedloanAuthItemDto.setCategory(0);
				speedloanAuthItemDto.setItemCode(statusDto.getItemCode());
				speedloanAuthItemDto.setItemName(statusDto.getItemName());
				speedloanAuthItemDto.setItemIcon(statusDto.getItemIcon());
				speedloanAuthItemDto.setItemDesc(statusDto.getItemDesc());
				speedloanAuthItemDto.setStatus(statusDto.getStatus());
			} else { // 补充认证项
				ProductSupplementItem productSupplementItem = productSupplementItemService.findById(specialItem.getItemId());
				CustSupplementItem custSupplementItem = custSupplementItemService.findByCustAndItemCode(cust, productSupplementItem.getItemCode());
				int status = custSupplementItem == null ? 0 : custSupplementItem.getStatus();
				speedloanAuthItemDto.setCategory(productSupplementItem.getSupplementCategoryId());
				speedloanAuthItemDto.setItemCode(productSupplementItem.getItemCode());
				speedloanAuthItemDto.setItemName(productSupplementItem.getItemName());
				speedloanAuthItemDto.setItemIcon(productSupplementItem.getItemIcon());
				speedloanAuthItemDto.setItemDesc(productSupplementItem.getItemDesc());
				speedloanAuthItemDto.setStatus(status + "");
			}
			result.add(speedloanAuthItemDto);
		}
		return result;
	}
	
	/**
	 * 查询没有做或者认证失败的认证项
	 * @author zhaoqi01
	 * @param cust
	 * @param productId
	 * @return
	 * @throws Exception
	 */
	public List<SpeedloanAuthItemDto> getUnDoOrFailedSpeedloanAuthItem(Cust cust, Long productId) throws Exception {
		List<SpeedloanAuthItemDto> result = new ArrayList<SpeedloanAuthItemDto>();
		List<SpeedloanAuthItemDto> speedloanAuthItems = this.getSpeedloanAuthItemsByCustAndProduct(cust, productId);
		for (SpeedloanAuthItemDto speedloanAuthItemDto : speedloanAuthItems) {
			String status = speedloanAuthItemDto.getStatus();
			if("0".equals(status) || "3".equals(status)) {
				result.add(speedloanAuthItemDto);
			}
		}
		return result;
	}
}
